﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;

public class LevelManager : MonoBehaviour
{
    public int leftBlockNumber;
    public Transform Tilemap_Block;
    public Player_LeLe player_LeLe;

    void Start()
    {
        player_LeLe = GameObject.FindWithTag("Player").GetComponent<Player_LeLe>();
        player_LeLe.Init();

        leftBlockNumber = Tilemap_Block.transform.childCount;
        GamePanel.Instance.Text_leftBlockNumber.text = leftBlockNumber.ToString();

        NotifacitionCenter.GetInstance().registerObserver("EVENT_Block_Dead", on_EVENT_Block_Dead);
    }

    public void on_EVENT_Block_Dead(NotifyEvent e)
    {
        Debug.Log("接收-EVENT_Block_Dead");

        leftBlockNumber--;
        
        GamePanel.Instance.Text_leftBlockNumber.text = leftBlockNumber.ToString();
        
        if (leftBlockNumber <= 0)
        {
            ShuaiManager.Instance.level++;
            ShuaiManager.Instance.EnterLevel();
        }
    }

    void OnDestroy()
    {
        NotifacitionCenter.GetInstance().removeObserver("EVENT_Block_Dead", on_EVENT_Block_Dead);
    }
    
}
